package net.xiaosaguo.mymall.product.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * description: Redisson 整合配置
 * <p>
 * 1. 导入依赖
 * 2. 注入 RedissonClient 实例
 * 3. 使用 RedissonClient
 *
 * @author xiaosaguo
 * @date 2020/06/26
 */
@Configuration
public class RedissonConfig {

    /**
     * description: 所有对 redisson 的使用都是通过 RedissonClient 对象
     *
     * @author xiaosaguo
     * @date 2020/06/26 04:32
     */
    @Bean(destroyMethod = "shutdown")
    public RedissonClient redisson() {
        // 1. 构造配置
        Config config = new Config();
        // Redis url should start with redis:// or rediss:// (for SSL connection)
        config.useSingleServer().setAddress("redis://192.168.235.131:6379");
        // 2. 根据 Config 创建客户端
        return Redisson.create(config);
    }

}
